<template>
  <div>
    <el-container style="height: 100vh; line-height: 60px">
      <el-header class="header-top-wrap">
        <div class="header-top">
          <el-dropdown>
            <i class="el-icon-setting" style="margin-right: 15px"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <router-link to="/admin/logout" style="color: #333"
                  >退出</router-link
                >
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <span>咕咕玉</span>
        </div>
      </el-header>
      <el-container class="container-wrap" style="overflow-y: auto">
        <el-aside width="200px">
          <!-- router 代表带起 vue-router 模式 index 代表跳转地址 -->
          <el-menu :default-openeds="['1']" router>
            <el-submenu index="1">
              <template slot="title"
                ><i class="el-icon-user"></i>员工管理</template
              >
              <el-menu-item index="/admin/staff/add"
                ><i class="el-icon-circle-plus-outline"></i
                >添加员工信息</el-menu-item
              >
              <el-menu-item index="/admin/staff/list"
                ><i class="el-icon-document"></i>员工信息列表</el-menu-item
              >
            </el-submenu>
            <el-submenu index="2">
              <template slot="title"
                ><i class="el-icon-postcard"></i>部门管理</template
              >
              <el-menu-item index="/admin/depart/add"
                ><i class="el-icon-plus"></i>添加部门信息</el-menu-item
              >
              <el-menu-item index="/admin/depart/list"
                ><i class="el-icon-notebook-2"></i>部门信息列表</el-menu-item
              >
            </el-submenu>
            <el-submenu index="3">
              <template slot="title"
                ><i class="el-icon-coin"></i>薪资管理</template
              >
              <el-menu-item index="/admin/salary/add"
                ><i class="el-icon-folder-add"></i>添加薪资信息</el-menu-item
              >
              <el-menu-item index="/admin/salary/list"
                ><i class="el-icon-wallet"></i>薪资信息列表</el-menu-item
              >
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 嵌套路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import { getDepart } from "../api/depart.js";
export default {
  name: "Admin",
  computed: {
    ...mapState(["depart"]),
  },
  async created() {
    let infos = await getDepart();
    let departs = [];
    for (let val in infos.data) {
      departs[val] = infos.data[val].name;
    }
    // console.log(departs);
    this.setDepart(departs);
    // console.log(this.depart);
  },
  methods: {
    ...mapMutations(["setDepart"]),
  },
};
</script>

<style scoped lang="less">
.header-top-wrap {
  background: linear-gradient(to right, #78bafd, #eca1a1);
  .header-top {
    float: right;
  }
}
</style>